package com.sheep.jucdemo.part1.part1_7;

/**
 * @Date 2022/4/6 21:38
 * @Created by sheep
 */
public class Test1_7_4 {

    public static void main(String[] args) throws InterruptedException {
        Thread threadOne = new Thread(new Runnable() {
            @Override
            public void run() {
                // 如果当前线程被中断则退出循环
                while (!Thread.currentThread().interrupted()) {
                    System.out.println("threadOne isInterrupted:" + Thread.currentThread().isInterrupted());
                }
                System.out.println("threadOne isInterrupted:" + Thread.currentThread().isInterrupted());
            }
        });
        // 启动子线程
        threadOne.start();
        Thread.sleep(1);
        System.out.println("threadOne.interrupt();。。。");
        threadOne.interrupt();
        threadOne.join();
        System.out.println("main thread is over!");
    }
}
